package com.kevin.learn;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel01 {
    public static void main(String[] args) throws Exception {
        String temp ="hello world! 哈哈";

        FileOutputStream fileOutputStream = new FileOutputStream("1.txt");
        FileChannel channel = fileOutputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(temp.getBytes());
        // 重置position
        byteBuffer.flip();
        // 向通道写数据
        channel.write(byteBuffer);
        
        fileOutputStream.close();
    }
}
